package com.zz.ecommerce.baseManage.rules.service;

import com.zz.ecommerce.baseManage.baseDict.dao.BaseDictDao;
import com.zz.ecommerce.baseManage.rules.bean.TDroolRule;
import com.zz.ecommerce.common.CommonDao;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TDroolRuleService {
    @Autowired
    CommonDao commonDao;
    @Autowired
    BaseDictDao baseDictDao;

    /**
     * 规则如果存在ruleId则更新，否则新增
     *
     * @param droolRule
     * @return
     */
    public String saveDroolRule(TDroolRule droolRule) {
        if (StringUtils.isEmpty(droolRule.getRuleId())) {
            commonDao.insert("T_DROOL_RULE", droolRule);
        } else {
            commonDao.update("T_DROOL_RULE", droolRule, " where rule_id=#{updateObj.ruleId}");
        }
        return "success";
    }

    /**
     * 批量更新状态
     *
     * @param ruleIds
     * @return
     */
    public String updateRuleStatus(String ruleIds, String status) {
        if (StringUtils.isNotEmpty(ruleIds) && StringUtils.isNotEmpty(status)) {
            String ids[] = ruleIds.split(",");
            for (String id : ids) {
                if (StringUtils.isNotEmpty(id)) {
                    baseDictDao.updateBySql("update T_DROOL_RULE set rule_status='" + status + "'" + "where rule_id='" + id + "'");
                }
            }
        }
        return "success";
    }

}
